package com.exam.Controller;

import com.exam.Entity.AnswerInfo;
import com.exam.Entity.ApiResult;
import com.exam.Service.AnswerInfoService;
import com.exam.util.ApiResultHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.Collections;
import java.util.List;
import java.util.Map;

@RestController
public class AnswerInfoController {
    @Autowired
    private AnswerInfoService answerInfoService;

    @GetMapping("/answerDetails/{page}/{size}")
    public ApiResult findAll(@PathVariable("page") Integer page, @PathVariable("size") Integer size) {
        ApiResult apiResult;
        List<AnswerInfo> res = answerInfoService.findAll(page,size);
        List<AnswerInfo> resForController = answerInfoService.findTotal(page,size);
        System.out.println("answerinfo表分页查询到了");
        // 构造返回数据
        Map<String, Object> data = new java.util.HashMap<>();
        data.put("records", res);               // 返回的试卷列表
        data.put("current", page);              // 当前页码
        data.put("size", size);                 // 每页大小
        data.put("total", resForController.size());          // 总记录数（列表长度）

        // 构建 ApiResult
        apiResult = ApiResultHandler.buildApiResult(200, "请求成功！", data);

        return apiResult;
    }

}
